Skip to content

RUBY-3901 Client backpressure with baseBackoffMS - #3103

Merged
comandeo-mongo merged 7 commits into
mongodb:masterfrom
comandeo-mongo:3901-client-backpressure
Aug 19, 2026
Merged

RUBY-3901 Client backpressure with baseBackoffMS#3103
comandeo-mongo merged 7 commits into
mongodb:masterfrom
comandeo-mongo:3901-client-backpressure

Conversation

@comandeo-mongo

@comandeo-mongo comandeo-mongo commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Implements the baseBackoffMS part of the client backpressure spec.

  • Bumps the handshake backpressure field from true to "2" to signal support for server-driven backoff.
  • Reads baseBackoffMS from the server's overload error response and uses it as the base of the exponential backoff, falling back to the driver default when absent or non-positive.
  • Fixes the exponent in the backoff formula: delay is now jitter * min(MAX_BACKOFF, base * 2**attempt), matching the spec. The same off-by-one is fixed in with_transaction backoff.
  • Rebuilds the retry policy in Client#with so a derived client picks up a changed max_adaptive_retries.

Updates unit and prose tests accordingly.

RUBY-3901

@comandeo-mongo
comandeo-mongo marked this pull request as ready for review August 18, 2026 12:18
@comandeo-mongo
comandeo-mongo requested a review from a team as a code owner August 18, 2026 12:18
@comandeo-mongo
comandeo-mongo requested review from jamis and a lite review from Copilot August 18, 2026 12:18
@comandeo-mongo comandeo-mongo changed the title 3901 client backpressure RUBY-3901 Client backpressure with baseBackoffMS Aug 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Ruby MongoDB driver’s client backpressure implementation and related specs to match updated client-backpressure behavior (new exponential backoff schedule, support for server-supplied baseBackoffMS, and updated handshake metadata).

Changes:

  • Adjust exponential backoff calculations (including with_transaction and backpressure retry loops) and update expectations in specs.
  • Add support for server-supplied baseBackoffMS and plumb the triggering error into backoff computation.
  • Ensure Client#with rebuilds the retry policy when maxAdaptiveRetries changes, and update handshake metadata backpressure value.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
spec/mongo/session/with_transaction_overload_spec.rb Updates expected overload backoff sleep duration in with_transaction specs.
spec/mongo/session_transaction_prose_spec.rb Updates expected summed backoff time to match new retry backoff schedule.
spec/mongo/server/app_metadata_backpressure_spec.rb Updates handshake backpressure expectation (but needs matcher/description fix).
spec/mongo/retryable/client_backpressure_prose_spec.rb Reworks prose tests to run against a real cluster using failpoints; updates timing logic.
spec/mongo/retryable/client_backpressure_no_backoff_prose_spec.rb Makes timing-based “no extra backoff” test deterministic by pinning jitter and recalculating bounds.
spec/mongo/retryable/backpressure_spec.rb Updates unit expectations for new exponential series and adds coverage for baseBackoffMS override.
spec/mongo/retryable/backpressure_options_spec.rb Adds coverage for Client#with correctly rebuilding retry policy for maxAdaptiveRetries.
lib/mongo/session.rb Passes error into overload backoff calculation and adjusts with_transaction retry backoff exponent.
lib/mongo/server/app_metadata.rb Changes handshake client_document[:backpressure] value to '2'.
lib/mongo/retryable/write_worker.rb Passes the last error into overload backoff computation for writes.
lib/mongo/retryable/retry_policy.rb Extends backoff_delay API to accept err: and forwards it to Backpressure.
lib/mongo/retryable/read_worker.rb Passes the last error into overload backoff computation for reads.
lib/mongo/retryable/backpressure.rb Implements server-supplied base backoff (baseBackoffMS) and updates exponential formula.
lib/mongo/retryable.rb Passes the error into overload backoff computation for generic overload retry helper.
lib/mongo/operation/result.rb Adds base_backoff_ms accessor to expose baseBackoffMS from server error replies.
lib/mongo/client.rb Centralizes retry policy construction and rebuilds policy on Client#with when maxAdaptiveRetries changes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +81 to +83
# Step 3.6: the sum of the two backoffs is 0.3 seconds. The
# 0.6-second window accounts for variance between the two runs.
expect((with_backoff - (no_backoff + 0.6)).abs).to be < 0.6
Comment on lines 7 to 10
it 'includes backpressure: true' do
metadata = described_class.new
expect(metadata.client_document[:backpressure]).to be true
expect(metadata.client_document[:backpressure]).to be '2'
end
@comandeo-mongo
comandeo-mongo merged commit 8222a3d into mongodb:master Aug 19, 2026
11 of 12 checks passed
@comandeo-mongo
comandeo-mongo deleted the 3901-client-backpressure branch August 19, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants